package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.mappers.BlackListMapper;
import com.tanhua.model.domain.BlackList;
import com.tanhua.model.domain.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public IPage<UserInfo> findByUserId(Long userId, int page, int pagesize) {
        //构建分页参数对象Page
        IPage<UserInfo> ip = new Page<>(page,pagesize);

        //调用方法分页（自定义编写 分页参数Page，sql条件参数）
        return blackListMapper.findBlackList(ip,userId);
    }

    @Override
    public void delete(Long userId, Long blackUserId) {
        LambdaQueryWrapper<BlackList> lqw = new LambdaQueryWrapper<>();
        lqw.eq(BlackList::getUserId,userId).eq(BlackList::getBlackUserId,blackUserId);
        blackListMapper.delete(lqw);
    }
}
